<html ng-app="app">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="../../build/common/ngEdit.css" rel="stylesheet">
		<script type="text/javascript" src="../../build/common/ngEdit.js"></script>
		
		<script type="text/javascript">
		    //------------用户选择框可选多人设置-----------------//
		    var conf = {
				selectNum:-1
			};
			var app = angular.module('app', ['baseDirective']);
			app.controller("ctrl", [ '$scope', 'baseService', function($scope, baseService) {
				 
				//-------------选择参与者-----------------------//
				$scope.openCustom = function() {
					$scope.data.scheduleParticipantList = new Array();
					CustomDialog.openCustomDialog('userSelector',function(data,dialog){
						var participants = "";
						for(var i = 0; i < data.length; i++) {
							participants += data[i].name;
							var a = new Object();
							a.participantorName = data[i].name;
							a.participantor = data[i].id;
							$scope.data.scheduleParticipantList.push(a);
							if(i < data.length - 1) {
								participants+=',';
							}
						}
						$scope.data.participantNames = participants;
						//$("#participant").val(participants);
						document.getElementById("participant").value=participants;
					    dialog.dialog('close');//关闭弹出框

					},conf);
				}
				//----------------创建、编辑日程-----------------//
				$scope.openDetail = function(id, action) {
					//debugger
					if($scope.data.type == "share" || $scope.data.type == "ilka") {
						var title = action == "edit" ? "编辑日程" : action == "add" ? "添加日程" : "查看日程";
						action =action == "edit" ? "Edit" : action == "add" ? "Create" : "Get";
						var url="scheduleParticipant" + action +"?scheduleId=" + $scope.data.id;
						if(!$.isEmpty(id)){
							url+='?id=' + id;
						}
						HT.window.openEdit(url, title, action, 'grid', 500, 500, null, null, id, true);
					} else {
						$.topCall.error("共享或共同任务才能添加参与者");
					}
				}
				//----------------删除参与者-----------------//
				$scope.itemDelete = function(itemId) {
					$.ajax({
			               url: '${ctx}/calendar/schedule/itemDelete',
			               data: {
			                   id: itemId,
			               },
			               success: function() {
			            	   location.reload();
			               }
			           });
				}
				//-------------------保存前监听事件------------------//
/* 				$scope.$on("beforeSaveEvent",function(event,data){
					if(Date.parse($scope.data.endTime) <= $scope.data.startTime || $scope.data.endTime <= $scope.data.startTime) {
						data.pass = false;
						$.topCall.error("结束日期不能小于开始日期");
					}
			    }); */
				//-----------------保存后监听事件-----------------//
				$scope.$on("afterSaveEvent",function(event,data){
					if(data.r == false) {
						parent.location.reload();
					}
					if(data.r == true) {
						location.reload();
					}
			    });
				//初始化选中时间：若选中一天，将开始时间改为早上9点，结束时间改为下午6点
				/* $scope.$on("afterLoadEvent",function(event,data){
					if("${param.startTime}") {
						var start = ${param.startTime}-8*60*60*1000;
						if(start%86400000 == 57600000) {
							start += 9*60*60*1000;
						}
						data.startTime = new Date(start);
					}
					if("${param.endTime}") {
						var end = ${param.endTime}-8*60*60*1000;
						if(end%86400000 == 57600000) {
							end -= 6*60*60*1000;
						}
						data.endTime = new Date(end);
					}
					
				}); */
			}]);
		</script>
	</head>
	
	<body ng-controller="ctrl" class="panel">
		
			<!-- 顶部按钮 -->
			<div class="panel-heading">
				<a class="btn btn-primary fa-save" ng-model="data" ab-save="/calendar/schedule/save"><span>保存</span></a>
				<a href="javascript:void(0)" class="btn btn-sm btn-primary fa-reply" onclick="javascript:$.Dialog.close(window);"> 返回</a>	
			</div>
			<form name="form" method="post" ng-model="data">
				<table class="form-table">
							<tr>								
								<th>标题:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.title"   ab-validate="{required:true}"  />
								</td>								
							</tr>
							
							<!-- <tr>								
								<th>任务连接:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.taskUrl"   ab-validate="{required:false,maxlength:765}"  />
								</td>								
							</tr> -->
							<tr>								
								<th>类型:</th>
								<td>
									<select class="form-control" type="text" ng-model="data.type"  ab-validate="{required:true,maxlength:192}">
									    <option value=""></option>
									    <option value="single">个人</option>
									    <option value="share">共享</option>
									    <option value="ilka">共同任务</option>
									</select>
								</td>								
							</tr>
							<!-- <tr>								
								<th>任务打开方式:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.openType"   ab-validate="{required:false,maxlength:192}"  />
								</td>								
							</tr> -->
							<!-- <tr>								
								<th>所属人:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.owner"   ab-validate="{required:false,maxlength:192}"  />
								</td>								
							</tr>
							<tr>								
								<th>所属人姓名:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.ownerName"   ab-validate="{required:false,maxlength:192}"  />
								</td>								
							</tr> -->
							<tr ng-if="data.type == 'share' || data.type == 'ilka'">								
								<th>参与者:</th>
								<td>
									<input id="participant" class="form-control" type="text" ng-model="data.participantNames"   ab-validate="{required:false}" readonly="readonly" />
									<span class="btn  btn-sm btn-primary fa  ng-scope" ng-click="openCustom()">选择</span>
								</td>								
							</tr>
							<tr>								
								<th>开始日期:</th>
								<td>
									<input ng-init="data.startTime = ${param.startTime}" class="form-control" type="text" ng-model="data.startTime" ab-date="yyyy-MM-dd HH:mm:ss"  ab-validate="{required:true}"  />
								</td>								
							</tr>
							<tr>								
								<th>结束日期:</th>
								<td>
									<input ng-init="data.endTime = ${param.endTime}" class="form-control" type="text" ng-model="data.endTime" ab-date="yyyy-MM-dd HH:mm:ss"  ab-validate="{required:true}"  />
								</td>								
							</tr>
							<tr>								
								<th>描述:</th>
								<td>
									<textarea class="form-control" type="text" style="width:500px" ng-model="data.remark"   ab-validate="{required:false}"  />
								</td>								
							</tr>
<!-- 							<tr>								
								<th>锁定:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.isLock"   ab-validate="{required:false,maxlength:30}"  />
								</td>								
							</tr> -->
							<!-- <tr>								
								<th>创建时间:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.createTime" ab-date  ab-validate="{required:false}"  />
								</td>								
							</tr>
							<tr>								
								<th>创建人:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.createBy"   ab-validate="{required:false,maxlength:192}"  />
								</td>								
							</tr> -->
<!-- 							<tr>								
								<th>版本:</th>
								<td>
									<input class="form-control" type="text" ng-model="data.rev"   ab-validate="{required:false,number:true,maxIntLen:10}"  />
								</td>								
							</tr> -->
				</table>
				
				
				<!-- <table class="table-grid" cellspacing="0">
					<tr>
						<td colspan="9">
							<div class="buttons">
								<a class="btn btn-primary fa-add" ng-click="openDetail('','edit')" >
									<span>添加</span>
								</a>
							</div>
						</td>
					</tr>
					<tr>
								<th>参与者名字</th>
								<th>参与者</th>
								<th>ilka完成比例</th>
								<th>ilka提交注释</th>
								<th>创建时间</th>
								<th>更新时间</th>
								<th>ilka实际开始时间</th>
								<th>ilka完成时间</th>
						<th>操作</th>
					</tr>
					<tr ng-repeat="item in data.scheduleParticipantList track by $index">
							<td>
								<input class="form-control" type="text" ng-model="item.participantorName"  ab-validate="{required:false,maxlength:765}"  />
							</td>
							<td>
								<input class="form-control" type="text" ng-model="item.participantor"  ab-validate="{required:false,maxlength:192}"  />
							</td>
							<td>
								<input class="form-control" type="text" ng-model="item.rateProgress"  ab-validate="{required:false,number:true,maxIntLen:10}"  />
							</td>
							<td>
								<input class="form-control" type="text" ng-model="item.submitComment"  ab-validate="{required:false}"  />
							</td>
							<td>
								<input class="form-control" type="text" ab-date ng-model="item.createTime" />
							</td>
							<td>
								<input class="form-control" type="text" ab-date ng-model="item.updateTime" />
							</td>
							<td>
								<input class="form-control" type="text" ab-date ng-model="item.actualStartTime" />
							</td>
							<td>
								<input class="form-control" type="text" ab-date ng-model="item.completeTime" />
							</td>
						<td>
							<a href="#" ng-click="itemDelete(item.id)" class="btn btn-sm btn-default fa-times"></a>
						</td>
					</tr>
				</table> -->
				
			</form>
		
	</body>
</html>